package com.cn.lotary.util;

import java.util.Date;

/**
 *
 * @author Jason May 21, 2011
 */
public class GlobalException {

    private final static String N = "\n";

    public GlobalException() {
    }

    /**
     * 发送邮件
     *
     * @param level 异常级别
     * @param e Exception
     */
    public static void setException(String level, Exception e) {
        String body =
                new Date()
                + e.getStackTrace()[0].getClassName()
                + N
                + e.getStackTrace()[0].getMethodName()
                + N
                + e.getStackTrace()[0].getLineNumber()
                + N
                + e.getLocalizedMessage();
        level = formatSubject(level, SystemConfig.PROJECT_NAME);
        Mailer.sendMail(null, null, level, body);
    }

    private static String formatSubject(String subject, String projectName) {
        return "Server -  " + ServerInfo.ServerIp + "  project -  " + projectName + "  Error -  " + subject;
    }
}
